import Vue from 'vue'
export default {
	data() {
		return {
			shareParams: {
				path: '/pages/tabs/home', // 首页路径
				title: '监控系统平台', // 标题-按照自己要求命名
				imageUrl: 'https://oss.sclec.com/uploads/20240812/f3ac9c2dad36abedb46b87f88330e9a5.jpg' // logo图片
			}
		}
	},
	computed: {},
	onLoad() {
		wx.showShareMenu({
			withShareTicket: true,
			menus: ["shareAppMessage", "shareTimeline"]
		})
	},
	onShareAppMessage(res) {
		let pages = getCurrentPages(); //获取当前页面栈的信息
		let currentPage = pages[pages.length - 1]; //获取到当前页面栈中最后一个页面的索引
		let token = uni.getStorageSync('token')
		let path = currentPage.route + `?userid=${token ? uni.getStorageSync('userInfo').id : 0}`
		if(this.$store.state.salonid){
			path = path + `&salonid=${this.$store.state.salonid}`
		}
		if(this.$store.state.otherid) {
			path = path + `&otherid=${this.$store.state.otherid}`
		}
		uni.hideShareMenu();
		if (res.from === 'menu') {// 来自页面内分享按钮
			if (token) {
				uni.showShareMenu();
				return {
					title: '',
					path: path, //后面是路径上要传递的参数
					imageUrl: '',
					success(res) {
						uni.showToast({
							title: "分享成功",
							success: () => {
								this.$store.commit('salonid',null)
								this.$store.commit('otherid',null)
							},
						});
					},
					fail(res) {
						uni.showToast({
							title: "分享失败",
							icon: "none",
						});
						this.$store.commit('salonid',null)
						this.$store.commit('otherid',null)
					},
				}
			} else {
				this.$store.commit('salonid',null)
				this.$store.commit('otherid',null)
				uni.showToast({
					title: '未登录状态下分享无法绑定上下级关系',
					icon: 'none'
				})
				uni.showShareMenu();
				return {
					title: "",
					path: path,
					imageUrl: '',
				};
			}
		}
	},
	methods: {}
}